package com.lfx.concurrent.phaser;

import java.util.Random;
import java.util.concurrent.Phaser;

/**
 * @author 李逢喜
 * create 2021/8/4
 */
public class MyThread extends Thread{


    private final Phaser phaser;




    private Random random=new Random();

    public MyThread(Phaser phaser,String name) {
        super(name);
        this.phaser = phaser;
    }

    @Override
    public void run() {

        try {
            System.out.println(super.getName()+"开始出发去公司");
            Thread.sleep(random.nextInt(1000));
            System.out.println(super.getName()+"到达公司");
            phaser.arriveAndAwaitAdvance();


            System.out.println(super.getName()+"开始笔数");
            Thread.sleep(random.nextInt(1000));
            System.out.println(super.getName()+"笔数结束");
            phaser.arriveAndAwaitAdvance();


            System.out.println(super.getName()+"开始面试");
            Thread.sleep(random.nextInt(1000));
            System.out.println(super.getName()+"面试结束");
            phaser.arriveAndAwaitAdvance();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
